﻿using System;
using Fjaspx.Common;

namespace Fjaspx.UI.Web
{
    public partial class _Remark : UserPage
    {
        /// <summary>
        /// Handles the Load event of the Page control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                string MexBoxContent = Fjaspx.Common.SystemCms.Read_File(Server.MapPath("~/administrator/SystemTemplate/MexBox.htm"), "utf-8");
                if (Request["NewsId"] != null && Request["userName"] != null && Request["contents"] != null)
                {
                    if (Request["NewsId"] != "" && Request["userName"] != "" && Request["contents"] != "")
                    {
                        int NewID = int.Parse((Request["NewsId"] == null ? "0" : Request["NewsId"]));
                        int userID = int.Parse((Request["userID"] == null ? "0" : Request["userID"]));
                        string userName = (Request["userName"] == null ? null : Request["userName"]);
                        string contents = (Request["contents"] == null ? null : Request["contents"]);
                        string Ip = Request.ServerVariables.Get("Remote_Addr").ToString();
                        DateTime Time = DateTime.Now;

                        Fjaspx.Sys.Model.ROYcms_remark model = new Fjaspx.Sys.Model.ROYcms_remark();
                        model.NewID = NewID;
                        model.userID = userID;
                        model.userName = userName;
                        model.contents = contents;
                        model.Ip = Ip;
                        model.Time = Time;

                        Fjaspx.Sys.Bll.ROYcms_remark bll = new Fjaspx.Sys.Bll.ROYcms_remark();
                        if (bll.Add(model) != 1)
                        {
                            MexBoxContent = MexBoxContent.Replace("{$IndexPage}", ___WebConfig.web_host);
                            MexBoxContent = MexBoxContent.Replace("{$message}", "录入成功！ <a href='/Comment.ashx?NewsId=" + Request["NewsId"] + "'>点击查看</a>");
                            Response.Write(MexBoxContent);
                            Fjaspx.Common.MessageBox.Show(this, "录入成功！");
                        }
                        else
                        {

                            MexBoxContent = MexBoxContent.Replace("{$IndexPage}", ___WebConfig.web_host);
                            MexBoxContent = MexBoxContent.Replace("{$message}", "参数错误！ ");
                            Response.Write(MexBoxContent);
                            Fjaspx.Common.MessageBox.Show(this, "参数错误！");
                        }
                    }
                }
                else {

                    MexBoxContent = MexBoxContent.Replace("{$IndexPage}", ___WebConfig.web_host);
                    MexBoxContent = MexBoxContent.Replace("{$message}", "参数错误！ ");
                    Response.Write(MexBoxContent);
                    Fjaspx.Common.MessageBox.Show(this, "参数错误！"); }
            }
        }
    }
}
